package com.bettem.modules.tourism.service.impl;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.bettem.common.utils.Constant;
import com.bettem.common.utils.PageUtils;
import com.bettem.common.utils.Query;
import com.bettem.common.utils.ShiroTokenUtils;
import com.bettem.modules.tourism.dao.TourismProductGroupPeriodDao;
import com.bettem.modules.tourism.entity.TourismProductGroupPeriodEntity;
import com.bettem.modules.tourism.entity.TourismProductPicEntity;
import com.bettem.modules.tourism.service.TourismProductGroupPeriodService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;


@Service("tourismProductGroupPeriodService")
public class TourismProductGroupPeriodServiceImpl extends ServiceImpl<TourismProductGroupPeriodDao, TourismProductGroupPeriodEntity> implements TourismProductGroupPeriodService {

    @Autowired
    private ShiroTokenUtils shiroTokenUtils;

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<TourismProductGroupPeriodEntity> page = this.selectPage(
                new Query<TourismProductGroupPeriodEntity>(params).getPage(),
                new EntityWrapper<TourismProductGroupPeriodEntity>().eq("delete_state", Constant.DELETE_STATE_NO)
        );

        return new PageUtils(page);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteByIds(String[] ids) {
        List<TourismProductGroupPeriodEntity> tourismProductGroupPeriodList=new ArrayList<>();
        TourismProductGroupPeriodEntity tourismProductGroupPeriodEntity=null;
        for(int i=0;i<ids.length;i++){
            tourismProductGroupPeriodEntity=new TourismProductGroupPeriodEntity();
            tourismProductGroupPeriodEntity.setId(ids[i]);
            tourismProductGroupPeriodEntity.setModifyUserId(shiroTokenUtils.getUserId());
            tourismProductGroupPeriodEntity.setModifyDate(new Date());
            tourismProductGroupPeriodEntity.setDeleteState(Constant.DELETE_STATE_YES);
            tourismProductGroupPeriodList.add(tourismProductGroupPeriodEntity);
        }
        this.updateBatchById(tourismProductGroupPeriodList);
    }

    @Override
    public void deleteProductGroupPeriodByProductId(Map<String, Object> params) {
        this.baseMapper.deleteProductGroupPeriodByProductId(params);
    }

}
